<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/1/18
 * Time: 9:44
 */
namespace app\controller\home;
use app\model\home\Website;
use think\facade\View;
// 启动会话

class Base
{
    protected $page = 1;
    protected $size = 10;
    protected $start_time = '';
    protected $end_time = '';
    protected $wid = 0;
    protected $website;
    protected $user;
    public function __construct()
    {
        global $wid;
        $this->page = input('page',1);
        $this->size = input('size',10);
        $this->wid = $wid = cache('wid');
        $web = ['web' => '未选择'];
        if (!empty($wid)) {
            $web = Website::find($wid);
            $this->website = $web;
        }
        View::assign('website',$web);
    }

    /**
     * 返回视图
     * @param string $view
     * @param array $data
     * @return string
     */
    protected function view($view = 'index', array $data = []){
        View::assign($data);
        return View::fetch($view);
    }

    protected function msg($data = [],string $msg = '成功',int $code = 200,int $http_code = 200){
        return json(['code' => $code,'msg' => $msg,'data' => $data],$http_code);
    }

    protected function fail($msg = 'fail',$code = 400,$http_code = 200){
        return json(['code' => $code,'msg' => $msg,'data' => (object)[]],$http_code);
    }

    protected function success($url = '/home/index/index',$msg = '操作成功'){
        return $this->view('/home/success',['msg' => $msg,'url' => $url]);
    }
}